package org.mulita.util;

import java.io.File;

import android.os.StatFs;

public class FileUtil {

	private FileUtil() {}
	
	/**
	 * Emulates File.getFreeSpace(File)
	 * @param file
	 * @return Free space available in the fs of the file
	 */
	public static long getFreeSpace(File file) {
		StatFs statFs = new StatFs(getDirPath(file));
		long availableBlocks = statFs.getAvailableBlocks();
		long blockSizeInBytes = statFs.getBlockSize();
		return availableBlocks * blockSizeInBytes;
	}

	/**
	 * Emulates File.getTotalSpace(File)
	 * @param file
	 * @return Total disk space available in the fs of the file
	 */
	public static long getTotalSpace(File file) {
		StatFs statFs = new StatFs(getDirPath(file));
		long availableBlocks = statFs.getBlockCount();
		long blockSizeInBytes = statFs.getBlockSize();
		return availableBlocks * blockSizeInBytes;
	}

	/**
	 * @param file
	 * @return returns path of file directory
	 */
	public static String getDirPath(File file) {
		if(file.isFile()) file=file.getParentFile();
		return file.getAbsolutePath();
	}
	
	
}
